/*
 * COPYRIGHT:	2010 Christopher Smith, licenced under the GNU GPL v2; see COPYING in the top level directory
 * PROJECT:		sdedit
 * FILE:		winhelp.h
 * PURPOSE:		helper header for missing/inaccurate win32 header items
 *				
 */

#ifndef _WIN64

#pragma warning(push)
#pragma warning(disable:4244)

#ifdef GetWindowLongPtrA

#undef SetWindowLongPtrA

FORCEINLINE LONG_PTR SetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
{
	return SetWindowLongA(hWnd, nIndex, dwNewLong);
}
#endif

#ifdef SetWindowLongPtrW

#undef SetWindowLongPtrW

FORCEINLINE LONG_PTR SetWindowLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
{
	return SetWindowLongW(hWnd, nIndex, dwNewLong);
}
#endif

#ifdef GetWindowLongPtrA

#undef GetWindowLongPtrA

FORCEINLINE LONG_PTR GetWindowLongPtrA(HWND hWnd, int nIndex)
{
	return GetWindowLongA(hWnd, nIndex);
}
#endif

#ifdef GetWindowLongPtrW

#undef GetWindowLongPtrW

FORCEINLINE LONG_PTR GetWindowLongPtrW(HWND hWnd, int nIndex)
{
	return GetWindowLongW(hWnd, nIndex);
}
#endif

#pragma warning(pop)

#endif //ifndef _WIN64

#ifndef MAXUCHAR

#define MAXUCHAR    0xff        // winnt
#define MAXUSHORT   0xffff      // winnt
#define MAXULONG    0xffffffff  // winnt

#endif //ifndef MAXUCHAR


#ifndef SE_DACL_UNTRUSTED
#define SE_DACL_UNTRUSTED	0x0040
#endif


#ifndef LABEL_SECURITY_INFORMATION
#define LABEL_SECURITY_INFORMATION 0x00000010
#endif

#ifndef SYSTEM_MANDATORY_LABEL_ACE_TYPE
#define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
#endif

#if defined(_WIN64)

#define _wtoiptr _wtoi64

#else

#define _wtoiptr _wtoi

#endif

#ifdef __in
#undef IN
#define IN __in
#endif //ifdef __in

#ifdef __in
#undef OUT
#define OUT __out
#endif //ifdef __out

//missing LSA API functions

typedef ULONG POLICY_SYSTEM_ACCESS_MODE;
typedef POLICY_SYSTEM_ACCESS_MODE *PPOLICY_SYSTEM_ACCESS_MODE;

#define POLICY_MODE_INTERACTIVE		(0x00000001L)
#define POLICY_MODE_NETWORK			(0x00000002L)
#define POLICY_MODE_SERVICE			(0x00000004L)

typedef struct POLICY_PRIVILEGE_DEFINITION {
	LSA_UNICODE_STRING Name;
	LUID LocalValue;
} POLICY_PRIVILEGE_DEFINITION, *PPOLICY_PRIVILEGE_DEFINITION;

//the following two sets of access bits are mainly guesses
#define ACCOUNT_VIEW					(0x00000001L)
#define ACCOUNT_ADJUST_PRIVILEGES		(0x00000002L)
#define ACCOUNT_ADJUST_QUOTAS			(0x00000004L)
#define ACCOUNT_ADJUST_SYSTEM_ACCESS	(0x00000008L)
#define ACCOUNT_ALL_ACCESS				(STANDARD_RIGHTS_REQUIRED | ACCOUNT_VIEW | ACCOUNT_ADJUST_PRIVILEGES | ACCOUNT_ADJUST_QUOTAS | ACCOUNT_ADJUST_SYSTEM_ACCESS)

#define SECRET_QUERY_VALUE				(0x00000001L)
#define SECRET_SET_VALUE				(0x00000002L)
#define SECRET_ALL_ACCESS				(STANDARD_RIGHTS_REQUIRED | SECRET_QUERY_VALUE | SECRET_SET_VALUE)


#ifdef __cplusplus
extern "C" {
#endif

NTSTATUS NTAPI LsaOpenAccount(IN HANDLE PolicyHandle, IN SID *AccountSid, IN ACCESS_MASK DesiredAccess, OUT HANDLE *AccountHandle);
NTSTATUS NTAPI LsaCreateAccount(IN HANDLE PolicyHandle, IN SID *AccountSid, IN ACCESS_MASK DesiredAccess, OUT HANDLE *AccountHandle);
NTSTATUS NTAPI LsaOpenSecret(IN HANDLE PolicyHandle, IN UNICODE_STRING *Name, IN ACCESS_MASK DesiredAccess, OUT HANDLE *SecretHandle);
NTSTATUS NTAPI LsaCreateSecret(IN HANDLE PolicyHandle, IN UNICODE_STRING *Name, IN ACCESS_MASK DesiredAccess, OUT HANDLE *SecretHandle);
NTSTATUS NTAPI LsaQuerySecurityObject(IN HANDLE ObjectHandle, IN SECURITY_INFORMATION SecurityInformation, OUT SECURITY_DESCRIPTOR_RELATIVE **SecurityDescriptor);
NTSTATUS NTAPI LsaSetSecurityObject(IN HANDLE ObjectHandle, IN SECURITY_INFORMATION SecurityInformation, IN SECURITY_DESCRIPTOR CONST *SecurityDescriptor);
NTSTATUS NTAPI LsaGetSystemAccessAccount(IN HANDLE AccountHandle, POLICY_SYSTEM_ACCESS_MODE *PreviousAccess);
NTSTATUS NTAPI LsaSetSystemAccessAccount(IN HANDLE AccountHandle, POLICY_SYSTEM_ACCESS_MODE Access);
NTSTATUS NTAPI LsaSetQuotasForAccount(IN HANDLE AccountHandle, IN QUOTA_LIMITS *QuotaLimits);
NTSTATUS NTAPI LsaGetQuotasForAccount(IN HANDLE AccountHandle, IN QUOTA_LIMITS *QuotaLimits); //check for possible double pointer/free in QuotaLimits
NTSTATUS NTAPI LsaEnumerateAccounts(IN HANDLE PolicyHandle, IN OUT LSA_ENUMERATION_HANDLE *EnumerationContext, OUT SID ***Buffer, IN ULONG PrefMaxCount, OUT ULONG *CountReturned);

#ifdef __cplusplus
}
#endif